package com.yb.web.goods;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yb.base.web.BaseAction;
import com.yb.bussiness.goods.TgPartService;
import com.yb.bussiness.goods.TgPartServiceImpl;
import com.yb.domain.goods.TgPart;
import com.yb.util.comm.Contants;
import com.yb.util.comm.RequestUtil;

public class TgPartAction extends BaseAction {
	private TgPartService service;
	private TgPart part;
	private List rows;
	private int total;
	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public TgPartAction() {
		service = new TgPartServiceImpl();
	}

	public TgPart getPart() {
		return part;
	}

	public void setPart(TgPart part) {
		this.part = part;
	}

	/**
	 * 保存
	 */
	public String saveOrUpdate() {
		try {
			if (!"".equals(part.getName())) {
				part.setName(URLDecoder.decode(part.getName(), "utf-8"));
			}
			if (!"".equals(part.getUser())) {
                part.setUser(URLDecoder.decode(part.getUser(), "utf-8"));
            }

			service.isSave(part);

			response.getWriter().print("1");
		} catch (Exception e) {
			e.printStackTrace();
			log.error("TgPartAction  申请保存失败", e);
			try {
				response.getWriter().print('2');
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			return null;
		}
		return null;
	}
	/**
	 * 查询
	 * 
	 * @return
	 */
	public String search() {
		String page = RequestUtil.getParam(request, "page", "");
		String row = RequestUtil.getParam(request, "rows", "");
		String auding = RequestUtil.getParam(request, "auding", "");
		Map<String, String> parameMap = new HashMap<String, String>();
		parameMap.put("page", page);
		parameMap.put("row", row);
		parameMap.put("auding", auding);
		List<TgPart> aclist = service.findByParameMap(parameMap);
		int count = service.count(parameMap);
		if (aclist != null) {
			total = count;
			rows = aclist;
		}
		return Contants.JSONSTRING_RESULT_NAME;

	}

	/**
	 * 删除
	 * 
	 * @return
	 */
	public String deleteById() {
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String idStr = RequestUtil.getParam(request, "ids", "");
			boolean isboolean = service.deleteById(idStr);
			out.println("{result:" + isboolean + "}");
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	/**
	 * 审核
	 * 
	 * @return
	 */
	public String updateMessageById() {
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String idStr = RequestUtil.getParam(request, "id", "");
			String autding = RequestUtil.getParam(request, "autding", "");
			boolean isboolean = service.updateAutingId(idStr, autding);
			out.println("{result:" + isboolean + "}");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}
